export default {
  namespace: 'cinema',
  state: {
    list: [],
  },
  reducers: {
    changeList(preState: any, action: any) {
      return { ...preState, list: action.payload };
    },
  },
  effects: {
    *getList(action: any, obj: any): any {
      const { call, put } = obj;
      let res = yield call(getListForCinema, action.payload.cityId);
      yield put({
        type: 'changeList',
        payload: res,
      });
    },
  },
};

async function getListForCinema(cityId: any) {
  let res = await fetch(
    `https://m.maizuo.com/gateway?cityId=${cityId}&ticketFlag=1&k=4681062`,
    {
      headers: {
        'X-Client-Info':
          '{"a":"3000","ch":"1002","v":"5.2.1","e":"1677227170557439510380545","bc":"110100"}',
        'X-Host': 'mall.film-ticket.cinema.list',
      },
    },
  ).then((res) => res.json());
  return res.data.cinemas;
}
